package com.cskaoyan.gateway.controller.shopping;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IHomeService;
import com.mall.shopping.IProductCateService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.AllProductCateRequest;
import com.mall.shopping.dto.AllProductCateResponse;
import com.mall.shopping.dto.HomePageResponse;
import com.mall.shopping.dto.NavListResponse;
import com.mall.user.annotation.Anoymous;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 晓帆
 * @version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("shopping")
@Api(tags = "shopcate",description = "商品分类")
public class IProductCateAndGoodsListController {

    @Reference(timeout = 3000, check = false)
    IProductCateService iProductCateService;
    @Reference(timeout = 3000, check = false)
    IHomeService iHomeService;


    /**
     * 显示商品详细分类
     * @return ResponseData
     */
    @GetMapping("/categories")
    @Anoymous
    public ResponseData showCategories(){
        AllProductCateRequest allProductCateRequest = new AllProductCateRequest();
        AllProductCateResponse allProductCate = iProductCateService.getAllProductCate(allProductCateRequest);
        if (allProductCate.getMsg().equals(ShoppingRetCode.SUCCESS.getMessage())){
            return new ResponseUtil().setData(allProductCate.getProductCateDtoList(),allProductCate.getMsg());
        }
        return new ResponseUtil().setErrorMsg(allProductCate.getMsg());
    }

    /**
     * 显示商品大类
     * @return ResponseData
     */
    @GetMapping("navigation")
    @Anoymous
    public ResponseData showNavigation(){
        NavListResponse allNav = iProductCateService.getAllNav();
        if (allNav.getMsg().equals(ShoppingRetCode.SUCCESS.getMessage())){
            return new ResponseUtil().setData(allNav.getPannelContentDtos());
        }
        return new ResponseUtil().setErrorMsg(allNav.getMsg());
    }

    /**
     * 商城首页
     * @return
     */
    @Anoymous
    @GetMapping("homepage")
    public ResponseData homePage(){
        HomePageResponse homepage = iHomeService.homepage();
        if (homepage.getMsg().equals(ShoppingRetCode.SUCCESS.getMessage())){
            return new ResponseUtil().setData(homepage.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(homepage.getMsg());
    }
}
